#include <iostream>
using namespace std;
int main() {
  auto logo = [](auto &self) -> int {
    char ch;
    string str;
    int dis = 0;
    while (cin >> ch) {
      if (ch == 'F') {
        int x;
        cin >> ch >> x;
        dis += x;
      } else if (ch == 'B') {
        int x;
        cin >> ch >> x;
        dis -= x;
      } else if (ch == 'R') {
        int x;
        char ch;
        //     EPEAT  10   [
        cin >> str >> x >> ch;
        dis += self(self) * x;
        // REPEAT 5[FD 100]REPEAT
      } else {  // ']'
        return dis;
      }
    }
    return dis;
  };
  cout << abs(logo(logo)) << endl;
}